package com.theaf.basemodule.web.controller;

import com.theaf.basemodule.common.api.CarTypeService;
import com.theaf.basemodule.common.dto.car.CarSysDTO;
import com.theaf.basemodule.common.dto.car.CarTypeDTO;
import com.theaf.basemodule.common.vo.AreaVO;
import com.theaf.basemodule.common.vo.car.BrandVO;
import com.theaf.basemodule.common.vo.car.CarSysVO;
import com.theaf.basemodule.common.vo.car.CarTypeVO;
import com.theaf.core.annotation.LogConfig;
import com.theaf.core.web.ResultHandler;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value="/cartype")
@Api(description="车型controller")
public class CarTypeController {
    @Autowired
    private CarTypeService carTypeService;

    @RequestMapping(value = "/brands",  method = RequestMethod.GET)
    @ApiOperation(value = "所有品牌",response = AreaVO.class)
    @ApiImplicitParam(value = "用途类型" , name = "useType" , dataType = "String" , paramType = "query")
    public Map brands(String useType){
        return ResultHandler.success(carTypeService.findAllBrand(useType));
    }

    @RequestMapping(value = "/delete/{id}",  method = RequestMethod.DELETE)
    @ApiOperation(value = "删除",response = Boolean.class)
    @ApiImplicitParam(value = "品牌、车系、车型id" , name = "id" , dataType = "long" , paramType = "path")
    public Map delete(@PathVariable Long id){
        carTypeService.delete(id);
        return ResultHandler.success(true);
    }

    @RequestMapping(value = "/carSyss/{brandid}",  method = RequestMethod.GET)
    @ApiOperation(value = "根据品牌查询车系",response = CarSysDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "品牌id", name = "brandid", dataType = "long", paramType = "path"),
            @ApiImplicitParam(value = "用途类型", name = "useType", dataType = "String", paramType = "query")
    })
    public Map carsyss(@PathVariable Long brandid,String useType){
        return ResultHandler.success(carTypeService.findCarSysByBrand(brandid,useType));
    }

    @RequestMapping(value = "/carTypes/{sysid}",  method = RequestMethod.GET)
    @ApiOperation(value = "根据车系查车型",response = CarTypeDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "车系id" , name = "sysid" , dataType = "long" , paramType = "path"),
            @ApiImplicitParam(value = "用途类型", name = "useType", dataType = "String", paramType = "query")
    })
    public Map cartypes(@PathVariable Long sysid,String useType){
        return ResultHandler.success(carTypeService.findCarTypeBySys(sysid,useType));
    }

    @RequestMapping(value = "/getCarType/{id}",  method = RequestMethod.GET)
    @ApiOperation(value = "查看车型详细数据",response = CarTypeDTO.class)
    @ApiImplicitParam(value = "车型id" , name = "id" , dataType = "long" , paramType = "path")
    public Map getcartype(@PathVariable Long id){
        return ResultHandler.success(carTypeService.findCarTypeById(id));
    }

    @RequestMapping(value = "/saveBrand",  method = RequestMethod.POST)
    @ApiOperation(value = "保存品牌", notes = "保存品牌", response = Boolean.class)
    @LogConfig
    public Object saveBrand(@RequestBody @ApiParam(name="提交数据",value="传入json格式",required=true) BrandVO brandVO){
        carTypeService.save(brandVO);
        return ResultHandler.success(true);
    }

    @RequestMapping(value = "/saveCarSys",  method = RequestMethod.POST)
    @ApiOperation(value = "保存车系", notes = "保存车系", response = Boolean.class)
    public Object saveCarSys(@RequestBody @ApiParam(name="提交数据",value="传入json格式",required=true) CarSysVO carSysVO){
        carTypeService.save(carSysVO);
        return ResultHandler.success(true);
    }

    @RequestMapping(value = "/saveCarType",  method = RequestMethod.POST)
    @ApiOperation(value = "保存车型", notes = "保存车型", response = Boolean.class)
    public Object saveCarType(@RequestBody @ApiParam(name="提交数据",value="传入json格式",required=true) CarTypeVO carTypeVO){
        carTypeService.save(carTypeVO);
        return ResultHandler.success(true);
    }
}
